
//V 240909
#ifndef _PT5F2307_H_
#define _PT5F2307_H_

/*  --------------------Extra SFR----------------------  */
//sfr(0xFFE8~0xFFFB) define
#ifdef _MAIN_C_
volatile unsigned char xdata MAP0    _at_ 0xFFE8;
volatile unsigned char xdata MAP1    _at_ 0xFFE9;
volatile unsigned char xdata MAP2    _at_ 0xFFEA;
volatile unsigned char xdata MAP3    _at_ 0xFFEB;
volatile unsigned char xdata MAP4    _at_ 0xFFEC;
volatile unsigned char xdata PWMCON0 _at_ 0xFFED;
volatile unsigned char xdata PWMCON1 _at_ 0xFFEE;
volatile unsigned char xdata PWMCON2 _at_ 0xFFEF;
volatile unsigned char xdata PWMD0L  _at_ 0xFFF0;
volatile unsigned char xdata PWMD0H  _at_ 0xFFF1;
volatile unsigned char xdata PWMD1L  _at_ 0xFFF2;
volatile unsigned char xdata PWMD1H  _at_ 0xFFF3;
volatile unsigned char xdata PWMD2L  _at_ 0xFFF4;
volatile unsigned char xdata PWMD2H  _at_ 0xFFF5;
volatile unsigned char xdata PWMD3L  _at_ 0xFFF6;
volatile unsigned char xdata PWMD3H  _at_ 0xFFF7;
volatile unsigned char xdata PWMD4L  _at_ 0xFFF8;
volatile unsigned char xdata PWMD4H  _at_ 0xFFF9;
volatile unsigned char xdata PWMD5L  _at_ 0xFFFA;
volatile unsigned char xdata PWMD5H  _at_ 0xFFFB;

#else
extern volatile unsigned char xdata MAP0    ;
extern volatile unsigned char xdata MAP1    ;
extern volatile unsigned char xdata MAP2    ;
extern volatile unsigned char xdata MAP3    ;
extern volatile unsigned char xdata MAP4    ;
extern volatile unsigned char xdata PWMCON0 ;
extern volatile unsigned char xdata PWMCON1 ;
extern volatile unsigned char xdata PWMCON2 ;
extern volatile unsigned char xdata PWMD0L  ;
extern volatile unsigned char xdata PWMD0H  ;
extern volatile unsigned char xdata PWMD1L  ;
extern volatile unsigned char xdata PWMD1H  ;
extern volatile unsigned char xdata PWMD2L  ;
extern volatile unsigned char xdata PWMD2H  ;
extern volatile unsigned char xdata PWMD3L  ;
extern volatile unsigned char xdata PWMD3H  ;
extern volatile unsigned char xdata PWMD4L  ;
extern volatile unsigned char xdata PWMD4H  ;
extern volatile unsigned char xdata PWMD5L  ;
extern volatile unsigned char xdata PWMD5H  ;
#endif

/*  --------------------BYTE Register----------------------  */
//sfr(0x80~0xFF) define
sfr SYSCON    = 0x80;
sfr SP        = 0x81;
sfr DP0L      = 0x82;
sfr DP0H      = 0x83;
sfr DP1L      = 0x84;
sfr DP1H      = 0x85;
sfr IOSET     = 0x86;
sfr PCON      = 0x87;
sfr P0        = 0x88;
sfr P0OD      = 0x89;
sfr P0PH      = 0x8A;
sfr P0PD      = 0x8B;
sfr P0OE      = 0x8C;
sfr P1OD      = 0x8D;
sfr P1PH      = 0x8E;
sfr P1PD      = 0x8F;
sfr P1        = 0x90;
sfr P1OE      = 0x91;
sfr DPS       = 0x92;
sfr P2PH      = 0x93;
sfr P2PD      = 0x94;
sfr P2OE      = 0x95;
sfr P3OD      = 0x96;
sfr P3PD      = 0x97;
sfr P2        = 0x98;
sfr P3OE      = 0x99;
sfr T0CON     = 0x9A;
sfr T0C       = 0x9B;
sfr T0OVR     = 0x9C;
sfr T1CON     = 0x9D;
sfr T1OVRL    = 0x9E;
sfr T1OVRH    = 0x9F;
sfr P3        = 0xA0;
sfr T1CL      = 0xA1;
sfr T1CH      = 0xA2;
sfr T2CON     = 0xA3;
sfr T2CL      = 0xA4;
sfr T2CH      = 0xA5;
sfr T2OVRL    = 0xA6;
sfr T2OVRH    = 0xA7;
sfr IE0       = 0xA8;
sfr IAPCON1   = 0xA9;
sfr IAPTRI    = 0xAA;
sfr IAPADRL   = 0xAB;
sfr IAPADRH   = 0xAC;
sfr IAPDAT    = 0xAD;
sfr IAPCON2   = 0xAE;
sfr P3PH      = 0xAF;
sfr IE1       = 0xB0;
sfr IF0       = 0xB1;
sfr IF1       = 0xB2;
sfr INTS      = 0xB3;
sfr INTEN     = 0xB4;
sfr IPH       = 0xB5;
sfr IPL       = 0xB6;
//sfr           = 0xB7;
sfr ADCON0    = 0xC8;
sfr ADCON1    = 0xC9;
sfr ADCON2    = 0xCA;
sfr ADCON3    = 0xCB;
sfr ADCCFG0   = 0xCC;
sfr ADCCFG1   = 0xCD;
sfr ADCCFG2   = 0xCE;
sfr ADCOL     = 0xCF;
sfr PSW       = 0xD0;
sfr ADCOH     = 0xD1;
sfr WDTSET    = 0xD2;
sfr WDTCON    = 0xD3;
sfr PWMIECFG  = 0xD4;
sfr PWMCNT    = 0xD5;
sfr P0WK      = 0xD6;
sfr P2OD      = 0xD7;
sfr RTCCON    = 0xD8;
sfr RTCSS     = 0xD9;
sfr RTCS      = 0xDA;
sfr RTCM      = 0xDB;
sfr RTCWH     = 0xDC;
sfr RTCDL     = 0xDD;
sfr RTCDH     = 0xDE;
sfr RTCAS     = 0xDF;
sfr ACC       = 0xE0;
sfr RTCAM     = 0xE1;
sfr RTCAH     = 0xE2;
sfr RTCMSS    = 0xE3;
sfr RTCCAL    = 0xE4;
sfr UAT0CON   = 0xE5;
sfr LVDCON0   = 0xE6;
sfr LVDCON1   = 0xE7;
sfr I2CCON0   = 0xE8;
sfr I2CSPD    = 0xE9;
sfr I2CSTATE  = 0xEA;
sfr I2CDAT    = 0xEB;
sfr I2CCON1   = 0xEC;
sfr B         = 0xF0;
sfr TLSEG0    = 0xF2;
sfr TLSEG1    = 0xF3;
sfr TLSEG2    = 0xF4;
sfr TLSEG3    = 0xF5;
sfr RTCIF     = 0xF8;
sfr UAT1CON   = 0xF9;
sfr UAT0SBUF  = 0xFA;
sfr UAT1SBUF  = 0xFB;
sfr UAT0SREL  = 0xFC;
sfr UAT0SREH  = 0xFD;
sfr UAT1SREL  = 0xFE;
sfr UAT1SREH  = 0xFF;

/*  --------------------Bit Register----------------------  */
////bit-operation
//sbit XTALO    = 0x80;

//sbit LPVMS    = 0x82;
//sbit OCDSM    = 0x83;
//sbit IRCLCAL  = 0x84;
//sbit XTALF    = 0x85;

//sbit WRST     = 0x87;

//sbit P00      = 0x88;
//sbit P01      = 0x89;
//sbit P02      = 0x8A;
//sbit P03      = 0x8B;
//sbit P04      = 0x8C;
//sbit P05      = 0x8D;
//sbit P06      = 0x8E;
//sbit P07      = 0x8F;

//sbit P10      = 0x90;
//sbit P11      = 0x91;
//sbit P12      = 0x92;
//sbit P13      = 0x93;
//sbit P14      = 0x94;
//sbit P15      = 0x95;
//sbit P16      = 0x96;
//sbit P17      = 0x97;

//sbit P20      = 0x98;
//sbit P21      = 0x99;
//sbit P22      = 0x9A;
//sbit P23      = 0x9B;
//sbit P24      = 0x9C;
//sbit P25      = 0x9D;
//sbit P26      = 0x9E;
//sbit P27      = 0x9F;	

//sbit P30      = 0xA0;
//sbit P31      = 0xA1;
//sbit P32      = 0xA2;
////sbit P33      = 0xA3;
////sbit P34      = 0xA4;
////sbit P35      = 0xA5;
////sbit P36      = 0xA6;
////sbit P37      = 0xA7;

//sbit INT0IE   = 0xA8;
//sbit INT1IE   = 0xA9;
//sbit T0IE     = 0xAA;
//sbit T1IE     = 0xAB;
//sbit T2IE     = 0xAC;
//sbit THIE     = 0xAD;
//sbit ADCIE    = 0xAE;
//sbit EA       = 0xAF;

//sbit RTCIE    = 0xB0;
//sbit LVDIE    = 0xB1;
//sbit PWMIE    = 0xB2;
//sbit UAT0RIE  = 0xB3;
//sbit UAT1RIE  = 0xB4;
//sbit UAT0TIE  = 0xB5;
//sbit UAT1TIE  = 0xB6;
//sbit LPVTIE   = 0xB7;

////sbit          = 0xBC;
////sbit          = 0xBD;
////sbit          = 0xBE;
////sbit          = 0xBF;


//sbit ADCVREF0 = 0xC8;
//sbit ADCVREF1 = 0xC9;
//sbit ADCVREF2 = 0xCA;
//sbit ADCEN    = 0xCB;
//sbit ADCS     = 0xCC;
//sbit ADCE     = 0xCD;
//sbit ADCCUR   = 0xCE;
//sbit ADCVO    = 0xCF;

//sbit P        = 0xD0;
//sbit DPS      = 0xD1;
//sbit OV       = 0xD2;
//sbit RS0      = 0xD3;
//sbit RS1      = 0xD4;
//sbit F0       = 0xD5;
//sbit AC       = 0xD6;
//sbit CY       = 0xD7;

//sbit CALS     = 0xD8;
//sbit RTCWE    = 0xD9;
//sbit HCEN     = 0xDA;
//sbit MCEN     = 0xDB;
//sbit SCEN     = 0xDC;
//sbit HSEN     = 0xDD;
//sbit MSEN     = 0xDE;
//sbit RTCEN    = 0xDF;

//sbit A0       = 0xE0;
//sbit A1       = 0xE1;
//sbit A2       = 0xE2;
//sbit A3       = 0xE3;
//sbit A4       = 0xE4;
//sbit A5       = 0xE5;
//sbit A6       = 0xE6;
//sbit A7       = 0xE7;

//sbit GC       = 0xE8;
////sbit          = 0xE9;
//sbit I2CSW    = 0xEA;
//sbit I2CIE    = 0xEB;
//sbit I2CMOD   = 0xEC;
//sbit I2CSTO   = 0xED;
//sbit I2CSTA   = 0xEE;
//sbit I2CEN    = 0xEF;

//sbit B0       = 0xF0;
//sbit B1       = 0xF1;
//sbit B2       = 0xF2;
//sbit B3       = 0xF3;
//sbit B4       = 0xF4;
//sbit B5       = 0xF5;
//sbit B6       = 0xF6;
//sbit B7       = 0xF7;

//sbit RTCMF    = 0xF8;
//sbit RTCHF    = 0xF9;
//sbit RTCAF    = 0xFA;
////sbit          = 0xFB;
////sbit          = 0xFC;
////sbit          = 0xFD;
////sbit          = 0xFE;
////sbit          = 0xFF;




sbit XTALO    = SYSCON^0;//0x80;
sbit CMODFS   = SYSCON^1;//0x81;
sbit LPVMS    = SYSCON^2;//0x82;
sbit OCDSM    = SYSCON^3;//0x83;
sbit LRCCAL   = SYSCON^4;//0x84;
sbit XTALF    = SYSCON^5;//0x85;
sbit CDCVS    = SYSCON^6;//0x86;
sbit WRST     = SYSCON^7;//0x87;

sbit P00      = P0^0;//0x88;
sbit P01      = P0^1;//0x89;
sbit P02      = P0^2;//0x8A;
sbit P03      = P0^3;//0x8B;
sbit P04      = P0^4;//0x8C;
sbit P05      = P0^5;//0x8D;
sbit P06      = P0^6;//0x8E;
sbit P07      = P0^7;//0x8F;

sbit P10      = P1^0;//0x90;
sbit P11      = P1^1;//0x91;
sbit P12      = P1^2;//0x92;
sbit P13      = P1^3;//0x93;
sbit P14      = P1^4;//0x94;
sbit P15      = P1^5;//0x95;
sbit P16      = P1^6;//0x96;
sbit P17      = P1^7;//0x97;

sbit P20      = P2^0;//0x98;
sbit P21      = P2^1;//0x99;
sbit P22      = P2^2;//0x9A;
sbit P23      = P2^3;//0x9B;
sbit P24      = P2^4;//0x9C;
sbit P25      = P2^5;//0x9D;
sbit P26      = P2^6;//0x9E;
sbit P27      = P2^7;//0x9F;	

sbit P30      = P3^0;//0xA0;
sbit P31      = P3^1;//0xA1;
sbit P32      = P3^2;//0xA2;
//sbit P33      = 0xA3;
//sbit P34      = 0xA4;
//sbit P35      = 0xA5;
//sbit P36      = 0xA6;
//sbit P37      = 0xA7;

sbit INT0IE   = IE0^0;//0xA8;
sbit INT1IE   = IE0^1;//0xA9;
sbit T0IE     = IE0^2;//0xAA;
sbit T1IE     = IE0^3;//0xAB;
sbit T2IE     = IE0^4;//0xAC;
sbit THIE     = IE0^5;//0xAD;
sbit ADCIE    = IE0^6;//0xAE;
sbit EA       = IE0^7;//0xAF;

sbit RTCIE    = IE1^0;//0xB0;
sbit LVDIE    = IE1^1;//0xB1;
sbit PWMIE    = IE1^2;//0xB2;
sbit UAT0RIE  = IE1^3;//0xB3;
sbit UAT1RIE  = IE1^4;//0xB4;
sbit UAT0TIE  = IE1^5;//0xB5;
sbit UAT1TIE  = IE1^6;//0xB6;
sbit LPVTIE   = IE1^7;//0xB7;

//sbit //0xB8;
//sbit //00xB9;
//sbit //00xBA;
//sbit //00xBB;
//sbit          = 0xBC;
//sbit          = 0xBD;
//sbit          = 0xBE;
//sbit          = 0xBF;

sbit ADCVREF0 = ADCON0^0;//0xC8;
sbit ADCVREF1 = ADCON0^1;//0xC9;
sbit ADCVREF2 = ADCON0^2;//0xCA;
sbit ADCEN    = ADCON0^3;//0xCB;
sbit ADCS     = ADCON0^4;//0xCC;
sbit ADCE     = ADCON0^5;//0xCD;
sbit ADCCUR   = ADCON0^6;//0xCE;
sbit ADCVO    = ADCON0^7;//0xCF;

sbit P        = PSW^0;//0xD0;
sbit F1       = PSW^1;//0xD1;
sbit OV       = PSW^2;//0xD2;
sbit RS0      = PSW^3;//0xD3;
sbit RS1      = PSW^4;//0xD4;
sbit F0       = PSW^5;//0xD5;
sbit AC       = PSW^6;//0xD6;
sbit CY       = PSW^7;//0xD7;

sbit CALS     = RTCCON^0;//0xD8;
sbit RTCWE    = RTCCON^1;//0xD9;
sbit HCEN     = RTCCON^2;//0xDA;
sbit MCEN     = RTCCON^3;//0xDB;
sbit SCEN     = RTCCON^4;//0xDC;
sbit HSEN     = RTCCON^5;//0xDD;
sbit MSEN     = RTCCON^6;//0xDE;
sbit RTCEN    = RTCCON^7;//0xDF;

sbit A0       = ACC^0;//0xE0;
sbit A1       = ACC^1;//0xE1;
sbit A2       = ACC^2;//0xE2;
sbit A3       = ACC^3;//0xE3;
sbit A4       = ACC^4;//0xE4;
sbit A5       = ACC^5;//0xE5;
sbit A6       = ACC^6;//0xE6;
sbit A7       = ACC^7;//0xE7;

sbit GC       = I2CCON0^0;//0xE8;
//sbit          = 0xE9;
sbit I2CSW    = I2CCON0^2;//0xEA;
sbit I2CIE    = I2CCON0^3;//0xEB;
sbit I2CMOD   = I2CCON0^4;//0xEC;
sbit I2CSTO   = I2CCON0^5;//0xED;
sbit I2CSTA   = I2CCON0^6;//0xEE;
sbit I2CEN    = I2CCON0^7;//0xEF;

sbit B0       = B^0;//0xF0;
sbit B1       = B^1;//0xF1;
sbit B2       = B^2;//0xF2;
sbit B3       = B^3;//0xF3;
sbit B4       = B^4;//0xF4;
sbit B5       = B^5;//0xF5;
sbit B6       = B^6;//0xF6;
sbit B7       = B^7;//0xF7;

sbit RTCMF    = RTCIF^0;//0xF8;
sbit RTCHF    = RTCIF^1;//0xF9;
sbit RTCAF    = RTCIF^2;//0xFA;
//sbit          = 0xFB;
//sbit          = 0xFC;
//sbit          = 0xFD;
//sbit          = 0xFE;
//sbit          = 0xFF;

/*  -----------------P00 bit Operation--------------------  */
#define P0OE_IN   P0OE  = 0xFF
#define P0OE0_IN  P0OE |= 0x01
#define P0OE1_IN  P0OE |= 0x02
#define P0OE2_IN  P0OE |= 0x04
#define P0OE3_IN  P0OE |= 0x08
#define P0OE4_IN  P0OE |= 0x10
#define P0OE5_IN  P0OE |= 0x20
#define P0OE6_IN  P0OE |= 0x40
#define P0OE7_IN  P0OE |= 0x80

#define P0OE_OUT  P0OE  = 0x00
#define P0OE0_OUT P0OE &=~0x01
#define P0OE1_OUT P0OE &=~0x02
#define P0OE2_OUT P0OE &=~0x04
#define P0OE3_OUT P0OE &=~0x08
#define P0OE4_OUT P0OE &=~0x10
#define P0OE5_OUT P0OE &=~0x20
#define P0OE6_OUT P0OE &=~0x40
#define P0OE7_OUT P0OE &=~0x80

#define P0PH_ON   P0PH  = 0x00
#define P0PH0_ON  P0PH &=~0x01
#define P0PH1_ON  P0PH &=~0x02
#define P0PH2_ON  P0PH &=~0x04
#define P0PH3_ON  P0PH &=~0x08
#define P0PH4_ON  P0PH &=~0x10
#define P0PH5_ON  P0PH &=~0x20
#define P0PH6_ON  P0PH &=~0x40
#define P0PH7_ON  P0PH &=~0x80

#define P0PH_OFF  P0PH  = 0xFF
#define P0PH0_OFF P0PH |= 0x01
#define P0PH1_OFF P0PH |= 0x02
#define P0PH2_OFF P0PH |= 0x04
#define P0PH3_OFF P0PH |= 0x08
#define P0PH4_OFF P0PH |= 0x10
#define P0PH5_OFF P0PH |= 0x20
#define P0PH6_OFF P0PH |= 0x40
#define P0PH7_OFF P0PH |= 0x80

#define P0PD_ON   P0PD  = 0xFF
#define P0PD0_ON  P0PD |= 0x01
#define P0PD1_ON  P0PD |= 0x02
#define P0PD2_ON  P0PD |= 0x04
#define P0PD3_ON  P0PD |= 0x08
#define P0PD4_ON  P0PD |= 0x10
#define P0PD5_ON  P0PD |= 0x20
#define P0PD6_ON  P0PD |= 0x40
#define P0PD7_ON  P0PD |= 0x80

#define P0PD_OFF  P0PD  = 0x00
#define P0PD0_OFF P0PD &=~0x01
#define P0PD1_OFF P0PD &=~0x02
#define P0PD2_OFF P0PD &=~0x04
#define P0PD3_OFF P0PD &=~0x08
#define P0PD4_OFF P0PD &=~0x10
#define P0PD5_OFF P0PD &=~0x20
#define P0PD6_OFF P0PD &=~0x40
#define P0PD7_OFF P0PD &=~0x80

#define P0OD_ON   P0OD  = 0xFF
#define P0OD0_ON  P0OD |= 0x01
#define P0OD1_ON  P0OD |= 0x02
#define P0OD2_ON  P0OD |= 0x04
#define P0OD3_ON  P0OD |= 0x08
#define P0OD4_ON  P0OD |= 0x10
#define P0OD5_ON  P0OD |= 0x20
#define P0OD6_ON  P0OD |= 0x40
#define P0OD7_ON  P0OD |= 0x80

#define P0OD_OFF  P0OD = 0x00
#define P0OD0_OFF P0OD &=~0x01
#define P0OD1_OFF P0OD &=~0x02
#define P0OD2_OFF P0OD &=~0x04
#define P0OD3_OFF P0OD &=~0x08
#define P0OD4_OFF P0OD &=~0x10
#define P0OD5_OFF P0OD &=~0x20
#define P0OD6_OFF P0OD &=~0x40
#define P0OD7_OFF P0OD &=~0x80

#define GET_P00_DATA  (P0&0x01)
#define GET_P01_DATA  (P0&0x02)
#define GET_P02_DATA  (P0&0x04)
#define GET_P03_DATA  (P0&0x08)
#define GET_P04_DATA  (P0&0x10)
#define GET_P05_DATA  (P0&0x20)
#define GET_P06_DATA  (P0&0x40)
#define GET_P07_DATA  (P0&0x80)

#define P0_H      P0  = 0xFF
#define P00_H     P0 |= 0x01
#define P01_H     P0 |= 0x02
#define P02_H     P0 |= 0x04
#define P03_H     P0 |= 0x08
#define P04_H     P0 |= 0x10
#define P05_H     P0 |= 0x20
#define P06_H     P0 |= 0x40
#define P07_H     P0 |= 0x80
                      
#define P0_L      P0  = 0x00
#define P00_L     P0 &=~0x01
#define P01_L     P0 &=~0x02
#define P02_L     P0 &=~0x04
#define P03_L     P0 &=~0x08
#define P04_L     P0 &=~0x10
#define P05_L     P0 &=~0x20
#define P06_L     P0 &=~0x40
#define P07_L     P0 &=~0x80

#define P0WK_ON   P0WK  = 0xFF
#define P0WK0_ON  P0WK |= 0x01
#define P0WK1_ON  P0WK |= 0x02
#define P0WK2_ON  P0WK |= 0x04
#define P0WK3_ON  P0WK |= 0x08
#define P0WK4_ON  P0WK |= 0x10
#define P0WK5_ON  P0WK |= 0x20
#define P0WK6_ON  P0WK |= 0x40
#define P0WK7_ON  P0WK |= 0x80

#define P0WK_OFF  P0WK  = 0x00
#define P0WK0_OFF P0WK &=~0x01
#define P0WK1_OFF P0WK &=~0x02
#define P0WK2_OFF P0WK &=~0x04
#define P0WK3_OFF P0WK &=~0x08
#define P0WK4_OFF P0WK &=~0x10
#define P0WK5_OFF P0WK &=~0x20
#define P0WK6_OFF P0WK &=~0x40
#define P0WK7_OFF P0WK &=~0x80

/*  -------------------P1 bit Operation--------------------  */
#define P1OE_IN   P1OE  = 0xFF
#define P1OE0_IN  P1OE |= 0x01
#define P1OE1_IN  P1OE |= 0x02
#define P1OE2_IN  P1OE |= 0x04
#define P1OE3_IN  P1OE |= 0x08
#define P1OE4_IN  P1OE |= 0x10
#define P1OE5_IN  P1OE |= 0x20
#define P1OE6_IN  P1OE |= 0x40
#define P1OE7_IN  P1OE |= 0x80

#define P1OE_OUT  P1OE  = 0x00
#define P1OE0_OUT P1OE &=~0x01
#define P1OE1_OUT P1OE &=~0x02
#define P1OE2_OUT P1OE &=~0x04
#define P1OE3_OUT P1OE &=~0x08
#define P1OE4_OUT P1OE &=~0x10
#define P1OE5_OUT P1OE &=~0x20
#define P1OE6_OUT P1OE &=~0x40
#define P1OE7_OUT P1OE &=~0x80

#define P1PH_ON   P1PH  = 0x00
#define P1PH0_ON  P1PH &=~0x01
#define P1PH1_ON  P1PH &=~0x02
#define P1PH2_ON  P1PH &=~0x04
#define P1PH3_ON  P1PH &=~0x08
#define P1PH4_ON  P1PH &=~0x10
#define P1PH5_ON  P1PH &=~0x20
#define P1PH6_ON  P1PH &=~0x40
#define P1PH7_ON  P1PH &=~0x80

#define P1PH_OFF  P1PH  = 0xFF
#define P1PH0_OFF P1PH |= 0x01
#define P1PH1_OFF P1PH |= 0x02
#define P1PH2_OFF P1PH |= 0x04
#define P1PH3_OFF P1PH |= 0x08
#define P1PH4_OFF P1PH |= 0x10
#define P1PH5_OFF P1PH |= 0x20
#define P1PH6_OFF P1PH |= 0x40
#define P1PH7_OFF P1PH |= 0x80

#define P1PD_ON   P1PD  = 0xFF
#define P1PD0_ON  P1PD |= 0x01
#define P1PD1_ON  P1PD |= 0x02
#define P1PD2_ON  P1PD |= 0x04
#define P1PD3_ON  P1PD |= 0x08
#define P1PD4_ON  P1PD |= 0x10
#define P1PD5_ON  P1PD |= 0x20
#define P1PD6_ON  P1PD |= 0x40
#define P1PD7_ON  P1PD |= 0x80

#define P1PD_OFF  P1PD  = 0x00
#define P1PD0_OFF P1PD &=~0x01
#define P1PD1_OFF P1PD &=~0x02
#define P1PD2_OFF P1PD &=~0x04
#define P1PD3_OFF P1PD &=~0x08
#define P1PD4_OFF P1PD &=~0x10
#define P1PD5_OFF P1PD &=~0x20
#define P1PD6_OFF P1PD &=~0x40
#define P1PD7_OFF P1PD &=~0x80

#define P1OD_ON   P1OD  = 0xFF
#define P1OD0_ON  P1OD |= 0x01
#define P1OD1_ON  P1OD |= 0x02
#define P1OD2_ON  P1OD |= 0x04
#define P1OD3_ON  P1OD |= 0x08
#define P1OD4_ON  P1OD |= 0x10
#define P1OD5_ON  P1OD |= 0x20
#define P1OD6_ON  P1OD |= 0x40
#define P1OD7_ON  P1OD |= 0x80

#define P1OD_OFF  P1OD  = 0x00
#define P1OD0_OFF P1OD &=~0x01
#define P1OD1_OFF P1OD &=~0x02
#define P1OD2_OFF P1OD &=~0x04
#define P1OD3_OFF P1OD &=~0x08
#define P1OD4_OFF P1OD &=~0x10
#define P1OD5_OFF P1OD &=~0x20
#define P1OD6_OFF P1OD &=~0x40
#define P1OD7_OFF P1OD &=~0x80

#define GET_P10_DATA  (P1&0x01)
#define GET_P11_DATA  (P1&0x02)
#define GET_P12_DATA  (P1&0x04)
#define GET_P13_DATA  (P1&0x08)
#define GET_P14_DATA  (P1&0x10)
#define GET_P15_DATA  (P1&0x20)
#define GET_P16_DATA  (P1&0x40)
#define GET_P17_DATA  (P1&0x80)

#define P1_H       P1  = 0xFF
#define P10_H      P1 |= 0x01
#define P11_H      P1 |= 0x02
#define P12_H      P1 |= 0x04
#define P13_H      P1 |= 0x08
#define P14_H      P1 |= 0x10
#define P15_H      P1 |= 0x20
#define P16_H      P1 |= 0x40
#define P17_H      P1 |= 0x80
                      
#define P1_L       P1  = 0x00
#define P10_L      P1 &=~0x01
#define P11_L      P1 &=~0x02
#define P12_L      P1 &=~0x04
#define P13_L      P1 &=~0x08
#define P14_L      P1 &=~0x10
#define P15_L      P1 &=~0x20
#define P16_L      P1 &=~0x40
#define P17_L      P1 &=~0x80

/*  ------------------P2 bit Operation--------------------  */
#define P2OE_IN   P2OE  = 0xFF
#define P2OE0_IN  P2OE |= 0x01
#define P2OE1_IN  P2OE |= 0x02
#define P2OE2_IN  P2OE |= 0x04
#define P2OE3_IN  P2OE |= 0x08
#define P2OE4_IN  P2OE |= 0x10
#define P2OE5_IN  P2OE |= 0x20
#define P2OE6_IN  P2OE |= 0x40
#define P2OE7_IN  P2OE |= 0x80

#define P2OE_OUT  P2OE  = 0x00
#define P2OE0_OUT P2OE &=~0x01
#define P2OE1_OUT P2OE &=~0x02
#define P2OE2_OUT P2OE &=~0x04
#define P2OE3_OUT P2OE &=~0x08
#define P2OE4_OUT P2OE &=~0x10
#define P2OE5_OUT P2OE &=~0x20
#define P2OE6_OUT P2OE &=~0x40
#define P2OE7_OUT P2OE &=~0x80

#define P2PH_ON   P2PH  = 0x00
#define P2PH0_ON  P2PH &=~0x01
#define P2PH1_ON  P2PH &=~0x02
#define P2PH2_ON  P2PH &=~0x04
#define P2PH3_ON  P2PH &=~0x08
#define P2PH4_ON  P2PH &=~0x10
#define P2PH5_ON  P2PH &=~0x20
#define P2PH6_ON  P2PH &=~0x40
#define P2PH7_ON  P2PH &=~0x80

#define P2PH_OFF  P2PH  = 0xFF
#define P2PH0_OFF P2PH |= 0x01
#define P2PH1_OFF P2PH |= 0x02
#define P2PH2_OFF P2PH |= 0x04
#define P2PH3_OFF P2PH |= 0x08
#define P2PH4_OFF P2PH |= 0x10
#define P2PH5_OFF P2PH |= 0x20
#define P2PH6_OFF P2PH |= 0x40
#define P2PH7_OFF P2PH |= 0x80

#define P2PD_ON   P2PD  = 0xFF
#define P2PD0_ON  P2PD |= 0x01
#define P2PD1_ON  P2PD |= 0x02
#define P2PD2_ON  P2PD |= 0x04
#define P2PD3_ON  P2PD |= 0x08
#define P2PD4_ON  P2PD |= 0x10
#define P2PD5_ON  P2PD |= 0x20
#define P2PD6_ON  P2PD |= 0x40
#define P2PD7_ON  P2PD |= 0x80

#define P2PD_OFF  P2PD  = 0x00
#define P2PD0_OFF P2PD &=~0x01
#define P2PD1_OFF P2PD &=~0x02
#define P2PD2_OFF P2PD &=~0x04
#define P2PD3_OFF P2PD &=~0x08
#define P2PD4_OFF P2PD &=~0x10
#define P2PD5_OFF P2PD &=~0x20
#define P2PD6_OFF P2PD &=~0x40
#define P2PD7_OFF P2PD &=~0x80

#define P2OD_ON   P2OD  = 0xFF
#define P2OD0_ON  P2OD |= 0x01
#define P2OD1_ON  P2OD |= 0x02
#define P2OD2_ON  P2OD |= 0x04
#define P2OD3_ON  P2OD |= 0x08
#define P2OD4_ON  P2OD |= 0x10
#define P2OD5_ON  P2OD |= 0x20
#define P2OD6_ON  P2OD |= 0x40
#define P2OD7_ON  P2OD |= 0x80

#define P2OD_OFF  P2OD   = 0x00
#define P2OD0_OFF P2OD &=~0x01
#define P2OD1_OFF P2OD &=~0x02
#define P2OD2_OFF P2OD &=~0x04
#define P2OD3_OFF P2OD &=~0x08
#define P2OD4_OFF P2OD &=~0x10
#define P2OD5_OFF P2OD &=~0x20
#define P2OD6_OFF P2OD &=~0x40
#define P2OD7_OFF P2OD &=~0x80

#define GET_P20_DATA  (P2&0x01)
#define GET_P21_DATA  (P2&0x02)
#define GET_P22_DATA  (P2&0x04)
#define GET_P23_DATA  (P2&0x08)
#define GET_P24_DATA  (P2&0x10)
#define GET_P25_DATA  (P2&0x20)
#define GET_P26_DATA  (P2&0x40)
#define GET_P27_DATA  (P2&0x80)

#define P2_H       P2  = 0xFF
#define P20_H      P2 |= 0x01
#define P21_H      P2 |= 0x02
#define P22_H      P2 |= 0x04
#define P23_H      P2 |= 0x08
#define P24_H      P2 |= 0x10
#define P25_H      P2 |= 0x20
#define P26_H      P2 |= 0x40
#define P27_H      P2 |= 0x80
                      
#define P2_L       P2  = 0x00
#define P20_L      P2 &=~0x01
#define P21_L      P2 &=~0x02
#define P22_L      P2 &=~0x04
#define P23_L      P2 &=~0x08
#define P24_L      P2 &=~0x10
#define P25_L      P2 &=~0x20
#define P26_L      P2 &=~0x40
#define P27_L      P2 &=~0x80

/*  ------------------P3 bit Operation--------------------  */
#define P3OE_IN   P3OE  = 0x07
#define P3OE0_IN  P3OE |= 0x01
#define P3OE1_IN  P3OE |= 0x02
#define P3OE2_IN  P3OE |= 0x04

#define P3OE_OUT  P3OE  = 0x00
#define P3OE0_OUT P3OE &=~0x01
#define P3OE1_OUT P3OE &=~0x02
#define P3OE2_OUT P3OE &=~0x04

#define P3PH_ON   P3PH  = 0x00
#define P3PH0_ON  P3PH &=~0x01
#define P3PH1_ON  P3PH &=~0x02
#define P3PH2_ON  P3PH &=~0x04

#define P3PH_OFF  P3PH  = 0x07
#define P3PH0_OFF P3PH |= 0x01
#define P3PH1_OFF P3PH |= 0x02
#define P3PH2_OFF P3PH |= 0x04

#define P3PD_ON   P3PD  = 0x07 
#define P3PD0_ON  P3PD |= 0x02
#define P3PD1_ON  P3PD |= 0x02
#define P3PD2_ON  P3PD |= 0x04

#define P3PD_OFF  P3PD  = 0x00
#define P3PD0_OFF P3PD &=~0x01
#define P3PD1_OFF P3PD &=~0x02
#define P3PD2_OFF P3PD &=~0x04

#define P3OD_ON   P3OD  = 0x07
#define P3OD0_ON  P3OD |= 0x01
#define P3OD1_ON  P3OD |= 0x02
#define P3OD2_ON  P3OD |= 0x04

#define P3OD_OFF  P3OD  = 0x00
#define P3OD0_OFF P3OD &=~0x01
#define P3OD1_OFF P3OD &=~0x02
#define P3OD2_OFF P3OD &=~0x04

#define GET_P30_DATA  (P3&0x01)
#define GET_P31_DATA  (P3&0x02)
#define GET_P32_DATA  (P3&0x04)

#define P3_H       P3  = 0x07
#define P30_H      P3 |= 0x01
#define P31_H      P3 |= 0x02
#define P32_H      P3 |= 0x04
                   
#define P3_L       P3  = 0x00
#define P30_L      P3 &=~0x01
#define P31_L      P3 &=~0x02
#define P32_L      P3 &=~0x04

#endif